#!/usr/bin/env python
# -*- coding: utf-8 -*-
from uidesign.CoffeForm_ui import Ui_Dialog
from PyQt5 import QtCore, QtWidgets
from rosservice.NavControl import NavControl
import sys

reload(sys)
sys.setdefaultencoding('utf8')


class CoffeForm(QtWidgets.QMainWindow, Ui_Dialog):
    def __init__(self, parentWindow):
        super(CoffeForm, self).__init__()
        self.setupUi(self)
        self.setWindowTitle("新增订单")
        self.parentWindow = parentWindow
        self.setFixedWidth(300)
        self.setFixedHeight(310)
        self.OK.clicked.connect(self.accept)
        self.Cancel.clicked.connect(self.reject)
        self.setCenter()
        self.init_options()

    def init_options(self):
        _translate = QtCore.QCoreApplication.translate
        sorted_keys = sorted(NavControl.m_target_point_maps_.keys())
        i = 1
        for key in sorted_keys:
            self.target_name.addItem(_translate("Dialog", key))
            i = i + 1
            # print("%s added to form option" % key)

    def setCenter(self):
        screen = QtWidgets.QDesktopWidget().screenGeometry()
        size = self.geometry()
        new_left = (screen.width() - size.width()) / 2
        new_top = (screen.height() - size.height()) / 2
        self.move(int(new_left), int(new_top))

    def clear(self):
        # self.coffe_table_num.clear()
        self.target_name.clear()
        self.target_message.clear()
        # self.coffe_status.clear()

    def accept(self):
        # a0 = self.target_name.text()
        a0 = self.target_name.currentText()
        a1 = self.target_message.text()
        # a3 = self.coffe_status.currentText()
        arr = [a0, a1]
        self.parentWindow.append_row(arr)
        self.clear()
        self.hide()
        pass

    def reject(self):
        self.clear()
        self.hide()
        pass
